﻿Ext.define('Examples.tree.menuitem.view.Form', {
    extend: 'Happy.form.Panel',
    alias: 'widget.menuitem-form',
    requires: [
        'Happy.form.action.Close',
        'Happy.form.action.Save',
        'Happy.form.field.Checkbox',
        'Happy.form.field.CkEditor',
        'Happy.form.field.Combobox',
        'Happy.form.field.TreeCombobox',
        'Happy.form.CheckboxGroup',
        'Happy.form.ImageContainer',
        'Happy.form.LinkContainer',
        'Examples.tree.menuitem.store.Store'
    ],

    initComponent: function () {
        var me = this;

        me.items = [
            {
                fieldLabel: 'Name',
                name: 'Name',
                allowBlank: false
            },
            {
                xtype: 'happy-tree-combobox',
                fieldLabel: 'Parent',
                name: 'ParentId',
                displayField: 'Name',
                valueField: 'Id',
                pathField: 'Id',
                pathSeparator: '\\',
                store: Ext.create('Examples.tree.menuitem.store.Store', {
                    autoLoad: true
                }),
                queryMode: 'local',
                treeNodeRenderer: function (values) {
                    var level = 0;
                    if (values.Id && values.Id != '\\') {
                        level = values.Id.split('\\').length - 1;
                    }

                    return Ext.String.repeat('&nbsp;', 4 * level) + values.Name;
                }
            }
        ];

        me.buttons = Happy.createActions([
            'save',
            'close'
        ]);

        me.callParent(arguments);
    }
});